<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of AreaLogic
 *
 * @author Administrator
 */
class AreaLogic extends BaseLogic{
    //put your code here
    private $areaTable;
    public function __construct() {
        parent::__construct();
        $this->areaTable=  $this->load("area");
        $this->table=  $this->areaTable;
    }
    /**
     * 通过城市id获得区列表
     * @param type $city_id 城市id
     * @return boolean 返回区列表
     */
    public function getAreaListByCid($city_id){
        if($city_id){
            $res=  $this->areaTable->select("*", "cityID={$city_id}");
            return $res;
        }
        return FALSE;
    }
    /**
     * 通过区域id获得区域信息
     * @param type $id  区域id
     * @return boolean 区域信息
     */
    public function getAreaInfoById($id){
         if($id){
            $res=  $this->areaTable->get_one("*","id={$id}");
            return $res;
        }
        return FALSE;
    }
    /**
     * 通过区域名称获得区域id
     * @param type $name 区域名称
     * @return int  区域id
     */
    public function getIdByName($name){
        if($name){
            $res=  $this->areaTable->get_one("*","area like '{$name}%'");
            return $res["id"];
        }
        return 0;
    }
    /**
     * 获得所有地区
     * @return type 地区列表
     */
    public function getAll(){
        $res=  $this->areaTable->select("*");
        return $res;
    }
    /**
     * 获得含有中国天气网id的地区列表
     * @return boolean  地区列表， 否则返回false
     */
    public function getHasWeatherAll(){
        $res=  $this->table->select("weatherID,id","weatherID is NOT NULL GROUP BY weatherID");
        if($res)
        {
            return $res;
        }
        return FALSE;
    }
}
